import { request } from '@/utils/requestWrapper';
import { tokenStore } from "@/store/tokenStore";

import type { API } from '@/backend/typings.d';

const tokenStoreInstance = tokenStore();

/** 添加收货地址 POST /api/address/add */
export async function addAddressUsingPost(
  body: API.AddressAddRequest,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponseLong_>({
    url: "/api/address/add",
    method: "POST",
    data: body,
    header: {
      'Authorization': tokenStoreInstance.getToken
    },
    ...(options || {})
  });
}

/** 删除收货地址 POST /api/address/delete */
export async function deleteAddressUsingPost(
  body: API.DeleteRequest,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponseBoolean_>({
    url: "/api/address/delete",
    method: "POST",
    data: body,
    ...(options || {})
  });
}

/** 获取收货地址详情 GET /api/address/get/vo */
export async function getAddressVoByIdUsingGet(
  params: {
    id: number;
  },
  options?: { [key: string]: any }
) {
  return request<API.BaseResponseAddressVO_>({
    url: "/api/address/get/vo",
    method: "GET",
    params,
    ...(options || {})
  });
}

/** 获取收货地址列表 POST /api/address/my/list/page/vo */
export async function listMyAddressVoByPageUsingPost(
  options?: { [key: string]: any }
) {
  return request<API.BaseResponsePageAddressVO_>({
    url: "/api/address/my/list/page/vo",
    method: "GET",
    header: {
      'Authorization': tokenStoreInstance.getToken
    },
    ...(options || {})
  });
}


/** 更新收货地址 POST /api/address/update */
export async function updateAddressUsingPost(
  body: API.AddressUpdateRequest,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponseBoolean_>({
    url: "/api/address/update",
    method: "POST",
    data: body,
    header: {
      'Authorization': tokenStoreInstance.getToken
    },
    ...(options || {})
  });
} 